import React from "react";



class ProductCar extends React.Component {
    constructor() {
        super()
        this.state = {
            counter: 0
        }
    }

    render() {
        return (
            <div>
                <h1>购物车:{this.state.counter}</h1>
                <CounterButton btnClick={this.incrementAction.bind(this)}/>
            </div>
        )
    }

    incrementAction(number) {
        this.setState({
            counter: this.state.counter + number
        })
    }
}

class CounterButton extends React.Component {

    render() {
        let btnClick = this.props.btnClick
        return (
            <button onClick={(e) => {btnClick(2)}}>添加</button>
        )
    }
}

export default ProductCar;